package net.jblog.struts.backoffice.form;

import java.io.UnsupportedEncodingException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import net.jblog.business.IConstantes;
import net.jblog.struts.tools.Conversions;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class PostForm extends ActionForm implements IConstantes {
	private static final long serialVersionUID = -3389128836996406500L;
	
	private String key;
	private Long id;

	private String title;
	private String url;
	private String content;
	private Long category;
	private String categoryName;
	
	private Date dateCreated;
	private Date dateModified;
	private Date datePublished;
	private int hoursPublished;
	private int minutesPublished;
	
	private String state;
	private String openComment;
	
	
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Date getDateCreated() {
		return dateCreated;
	}
	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}
	public Date getDateModified() {
		return dateModified;
	}
	public void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}
	public Date getDatePublished() {
		return datePublished;
	}
	public String getDatePublishedStr() {
		return Conversions.dateToString(datePublished);
	}
	public void setDatePublished(Date datePublished) {
		this.datePublished = datePublished;
	}
	public void setDatePublishedStr(String datePublished) {
		this.datePublished = Conversions.stringToDate(datePublished);
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getOpenComment() {
		return openComment;
	}
	public void setOpenComment(String openComment) {
		this.openComment = openComment;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public int getHoursPublished() {
		return hoursPublished;
	}
	public void setHoursPublished(int hoursPublished) {
		this.hoursPublished = hoursPublished;
	}
	public int getMinutesPublished() {
		return minutesPublished;
	}
	public void setMinutesPublished(int minutesPublished) {
		this.minutesPublished = minutesPublished;
	}
	
	
	public Long getCategory() {
		return category;
	}
	public void setCategory(Long category) {
		this.category = category;
	}
	public String getCategoryName() {
		return categoryName;
	}
	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}
	@Override
	public String toString() {
		StringBuffer str = new StringBuffer();
		str.append("{ PostForm :")
			.append("[title=").append(this.getTitle()).append("],")
			.append("[content=").append(this.getContent()).append("],")
		.append("}");
		return str.toString();
	}
	
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
	 	try {
	 		request.setCharacterEncoding("ISO-8859-1");
	 		
	 		this.setKey(null); this.setId(null);

	 		this.setTitle(null); this.setUrl(null);	this.setContent(null);
	 		this.setCategory(null);
	 		this.setDateCreated(null); this.setDateModified(null); this.setDatePublished(null);
	 		
	 		this.setState(POST_STATE_DRAFT); this.setOpenComment(null);
	 	} catch (UnsupportedEncodingException e) {
	 		e.printStackTrace();
	 	}
	 	super.reset(mapping, request);
	 }
	/*@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		try {
	 		request.setCharacterEncoding("ISO-8859-1");
	 	} catch (UnsupportedEncodingException e) {
	 		e.printStackTrace();
	 	}
	 	return super.validate(mapping, request);
	}
	*/
	
		
	 
}
